package com.sensen.mapper;


import com.sensen.common.GeneralMapper;
import com.sensen.model.User;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created by Administrator on 2017/10/2.
 */
@Mapper
@Component
public interface UserMapper extends GeneralMapper<User> {

    //以下方法用于演示，当通用Mapper不能买足需求时，可以自己扩展相应的方法
    //不允许查询参数为空的情况
    @Select({
            "select",
            "p_id, p_name, p_age",
            "from person",
            "where  p_age between #{startAge} and #{endAge}"
    })
    @Results({
            @Result(column="p_id", property="pId", jdbcType= JdbcType.INTEGER, id=true),
            @Result(column="p_name", property="pName", jdbcType=JdbcType.VARCHAR),
            @Result(column="p_age", property="pAge", jdbcType=JdbcType.INTEGER)
    })
    List<User> queryListByParam(User person);

    //允许查询参数为空的情况
    @SelectProvider(type = UserSqlProvider.class,method = "selectSelective")
    @Results({
            @Result(column="p_id", property="pId", jdbcType= JdbcType.INTEGER, id=true),
            @Result(column="p_name", property="pName", jdbcType=JdbcType.VARCHAR),
            @Result(column="p_age", property="pAge", jdbcType=JdbcType.INTEGER)
    })
    List<User> queryListByParamSelective(User person);


}
